/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.Description;
import entity.Langue;
import entity.Produit;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author livetnediser
 */
@Stateless
public class DescriptionFacade extends AbstractFacade<Description> {
    @PersistenceContext(unitName = "SexyShopPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public DescriptionFacade() {
        super(Description.class);
    }
    
    public Description findByProductLangue(Produit product, Langue langue) {
        List<Description> aux = em.createQuery("SELECT d FROM Description d WHERE d.iddescription = :iddes AND d.idLangue = :langue")
        .setParameter("iddes", product.getIdDescription())
        .setParameter("langue", langue)
        .getResultList();
	if(aux != null && aux.size()>0){
	    return aux.get(0);
	} else{
	    return null;
	}
    }
    
   /* public int antIdDesc() {
        List<Integer> aux = em.createQuery("SELECT d.iddescription FROM Description d WHERE d.iddescription = MAX(d.iddescription)")
        .getResultList();
	if(aux != null && aux.size()>0){
	    return aux.get(0);
	} else{
	    return -1;
	}
    }*/
    
}
